package Offer041;

import java.util.LinkedList;

/**
 * 滑动窗口的平均值
 *
 * @author 23737
 * @time 2021.12.19
 */
public class Test {
    public static void main(String[] args) {

    }
}

class MovingAverage {
    int len;
    double sum = 0;
    LinkedList<Integer> list;

    public MovingAverage(int size) {
        list = new LinkedList<>();
        len = size;
    }

    public double next(int val) {
        list.add(val);
        sum += val;
        while (list.size() > len) {
            sum -= list.removeFirst();
        }
        return sum / list.size();
    }
}